package newStreaming

import org.apache.spark.streaming.{Durations, StreamingContext}
import org.apache.spark.{SparkConf, SparkContext}

object wordCountDS {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
    sparkConf.setAppName("wordCountDS")
    sparkConf.setMaster("local[4]")
    val sparkContext = new SparkContext(sparkConf)
    val ssc = new StreamingContext(sparkContext, Durations.seconds(5))
    // 先去node1 启动 nc -lk 9999
    val ds = ssc.socketTextStream("node2", 9999)
    // word [1,1,1,1]
    ds.flatMap(_.split(",")).map((_, 1)).reduceByKey(_ + _).print()

    ssc.start()
    ssc.awaitTermination()
    ssc.stop()
  }
}
